package cn.shiwei.quartz.job;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 定时任务业务处理类，我们继承QuartzJobBean
 * 重写executeInternal方法来实现具体的定时业务逻辑
 */
@Component // 交给spring管理
public class PrintTimeJob extends QuartzJobBean {


    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        // 通过context获取JobDetail中关联的数据 // 获取jobdetail再获取jobdadamap再同那个锅键获取值
        String msg = context.getJobDetail().getJobDataMap().getString("params");
        String name = context.getJobDetail().getKey().getName();
        System.out.println(name + " :"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "---" + msg);
    }
}

